/*
 * Copyright 2003-2007 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

package com.colony.container.zone;

import com.argot.remote.MetaLocation;
import com.argot.remote.MetaObject;
import com.colony.ColonyException;
import com.colony.IContainer;
import com.colony.zone.CRL;
import com.colony.zone.IZone;
import com.colony.zone.ZoneException;
import com.colony.zone.process.SystemRealm;

public class RealmContainer
implements IContainer
{
	public SystemRealm _realm;
	
	public RealmContainer( SystemRealm realm )
	{
		_realm = realm;
	}

	public Object getObject( MetaLocation location )
	{
		CRL crl = (CRL) location;
		
		try
		{
			return _realm.find( crl );
		}
		catch (ZoneException e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public void addObject( MetaObject metaObject, Object object )
	throws ColonyException
	{
		throw new ColonyException("not implemented");
	}
	
	public void addObject( MetaLocation location, String type, Object object )
	throws ColonyException
	{
		if (!(location instanceof CRL))
		{
			throw new ColonyException("location not instance of CRL");
		}
		
		CRL crl = (CRL) location;
		crl.getLocation();
		try
		{
			IZone zone = (IZone) _realm.get( crl.getLocation() );
			if (zone == null)
			{
				throw new ColonyException("location not found:"+crl.getLocation());
			}
			zone.put( crl.getName(), object );
		}
		catch (ZoneException e)
		{
			throw new ColonyException(e.getMessage(),e);
		}
		
	}

}
